package com.zking.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * Created by OWen on 2023-2023/11/27, project: springboot1206.
 * <p>
 * Author: OWen
 * Create Date: 2023/11/27
 * Project: com.zking.dto in project: springboot1206
 * <p>
 * Notice: If you are using this class or file, check it and do some modification.
 */
@Data @AllArgsConstructor @NoArgsConstructor
// ResultDto<User> | ResultDto<List<User>> | ResultDto<Page<User>> | ResultDto<Void>
public class ResultDto<T> {
    private int code;
    private String message;
    private T data;
    
    public static <U> ResultDto<U> success(U data) {
        ResultDto<U> resultDto = new ResultDto<>();
        resultDto.setCode(0);
        resultDto.setData(data);
        return resultDto;
    }
    
    public static <U> ResultDto<U> fail(int code, String message) {
        ResultDto<U> resultDto = new ResultDto<>();
        resultDto.setCode(code);
        resultDto.setMessage(message);
        return resultDto;
    }
    
    public static <U> ResultDto<U> fail(int code) {
        return fail(code, null);
    }
}
